package com.example.fastdfsdemo.controller;

import com.example.fastdfsdemo.entity.FastDFSFile;
import com.example.fastdfsdemo.service.FastDFSService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Description
 *
 * @author : Charles
 * @date : 2020/12/17
 */
@Slf4j
@Controller
public class PageController {

    @Autowired
    private FastDFSService dfsService;

    /**
     * 页面路径
     * @param model
     * @return
     */
    @GetMapping("/{path}.html")
    public String page(final Model model, @PathVariable(value="path") String path) {
        //model.addAttribute("msg", "首页");
        return path;
    }

    @RequestMapping("/download/list")
    public String downloadFile(ModelMap model){
        //返回所有的用户图片列表
        List<FastDFSFile> filePath = dfsService.getUploadFilePath();
        if(filePath.size() == 0){
            log.info(">>>>>>>>>>>>>>>>用户文件目录获取失败:");
        } else {
            model.put("filePathList", filePath);
            log.info(">>>>>>>>>>>>>>>>用户文件目录获取成功:");
        }
        return "showImage";
    }

}
